﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Entity;
using School.Entities;
using School.Common;
using School.Accounting;

namespace School.Pages.Accounting
{
    public partial class PayLatePayment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            byte Type = 3;
            decimal paid = 0;
            long v = 0;
            DateTime voucherDate = DateTime.Now;

            byte.TryParse(Request.QueryString["Type"], out Type);

            switch (Type)
            {
                case 0:
                    long student = 0;

                    if (long.TryParse(Request.QueryString["Student"], out student) && decimal.TryParse(Request.QueryString["Paid"], out paid))
                    {
                        DateTime.TryParse(Request.QueryString["date"], out voucherDate);
                        v = LatePayment.PayBalance(student, paid, voucherDate);
                    }
                    else
                        Response.End();
                    break;

                case 1:
                    long PaymentOrderNumber = 0;

                    if (long.TryParse(Request.QueryString["PaymentOrder"], out PaymentOrderNumber) && decimal.TryParse(Request.QueryString["Paid"], out paid))
                    {
                        DateTime.TryParse(Request.QueryString["date"], out voucherDate);

                        v = LatePayment.PayVoucher(PaymentOrderNumber, paid, voucherDate);
                    }
                    else
                        Response.End();
                    break;

                case 2:
                    long payment = 0;
                    long st = 0;

                    if (long.TryParse(Request.QueryString["Payment"], out payment) && long.TryParse(Request.QueryString["Student"], out st) && decimal.TryParse(Request.QueryString["Paid"], out paid))
                    {
                        DateTime.TryParse(Request.QueryString["date"], out voucherDate);
                        v = LatePayment.PayPayment(payment, st, paid, voucherDate);
                    }
                    else
                        Response.End();
                    break;

                default:
                    Response.End();
                    break;
            }

            if (v > 0)
                Response.Redirect("VoucherPayment.aspx?Number=" + v.ToString() + "&Print=1");
        }
    }
}